package io.bdmc.modules.bss.controller;

import java.io.IOException;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.bdmc.common.utils.R;
import io.bdmc.common.websocket.MyWebSocket;
import io.netty.util.internal.StringUtil;

@RestController
@RequestMapping("/bss/msg")
public class MessageController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping("/alarm")
    public R dev_info(@RequestBody(required = false) Map<String, String> req) {

        String sim = req.get("sim");
        if(StringUtil.isNullOrEmpty(sim)){
            return R.ok();
        }
        try {
            MyWebSocket.sendInfo(JSONObject.toJSONString(req));
        } catch (IOException e) {
            logger.debug(e.getMessage());
            e.printStackTrace();
        }
        return R.ok();
    }
}